const {tagModel} = require("../mongdb");
const {success,fail} = require("../toast") //方法改引入多个方法
/*
get  ctx.query
post ctx.request.body
delete ctx.request.body
put     ctxquery    ctx.request.body
*/
module.exports=function test(router){
router.get("/tag", async ctx=>{
        try { //方法封装过后
            const data = await tagModel.find({});
                // console.log(data)
            return success(ctx,data);
        } catch (error) {
            return fail(ctx,error);
        }

    })

//增加
router.post("/tag",async ctx=>{
    try { //方法封装过后
        const data = await  tagModel.create(ctx.request.body);
        return success(ctx,data);
    } catch (error) {
        return fail(ctx,error);  
    }
    })
    //删除
    router.delete("/tag",async ctx=>{
    try { //方法封装过后
        const data = await  tagModel.deleteOne(ctx.request.body);
        return success(ctx,data);
    } catch (error) {
        return fail(ctx,error);  
    }
    })
}

